<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:text name="survey.list.title"/></title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
</head>
<body>
<s:set name="siteId" value="#session['CURRENT_SITE'].siteId"></s:set>
<div id="wrapper">
	<div id="main_box">
	<div class="curmb"><s:text name="your.site.position"/>:<a href="${ctx}/main.action"><s:text name="homepage"/></a><span>></span><s:text name="survey.title"/></div>
	<div class="listtit" id="listtit"><p><span><strong><s:text name="survey.list.title"/></strong></span></p></div>
	<s:form action="survey-list" id="search_form">
	<div class="searchbox">
		<table class="searchTable">
			<tbody id="searchTable">
				<tr>
					<td><label for="qry_surveyTitle"><s:text name="survey.surveyTitle"/>: </label></td>
					<td><s:textfield name="survey.surveyTitle"  cssClass="txtsearch" id="qry_surveyTitle"  maxlength="30"  /></td>
					<td><label for="qry_surveyStatus"><s:text name="survey.surveyStatus"/>: </label></td>
					<td>
						<s:select name="survey.isEnebleForPage" list="dicSurveyStatus" listKey="dictionaryKey" listValue="dictionaryValue" value="%{survey.surveyStatus}" cssClass="selectClass" headerKey="" headerValue="请选择"/>
					</td>
					<td><input type="button" value="<s:text name="query"/>" class="btnsearch" id="search_btn"/></td>
				</tr>
			</tbody>
		</table>
		<div class="clear"></div>
	</div>
	
	<div class="listoperate">
		<span class="cssa">
		<s:if test="%{authLicence('2_2_4',#siteId)}">
			<input id="top_new_btn" type="button" value="<s:text name="new"/>" class="btnadd"/>
		</s:if>
		<s:else>
			<input id="top_new_btn" type="button" disabled="disabled" value="<s:text name="new"/>" class="btnadd"/>
		</s:else>
		</span>
		<span>
		<s:if test="%{authLicence('2_2_4',#siteId)}">
			<input type="button" value="<s:text name="anti-selection"/>" class="btnlist2" id="top_anti_btn"/>
			<input type="button" value="<s:text name="delete"/>" class="btnlist2" id="top_del_btn"/>
			<input type="button" value="<s:text name="enable"/>" class="btnlist2" id="top_enable_btn"/>
			<input type="button" value="<s:text name="disable"/>" class="btnlist2" id="top_disable_btn"/>
		</s:if>
		<s:else>
			<input type="button" disabled="disabled" value="<s:text name="anti-selection"/>" class="btnlist2" id="top_anti_btn"/>
			<input type="button" disabled="disabled" value="<s:text name="delete"/>" class="btnlist2" id="top_del_btn"/>
			<input type="button" disabled="disabled" value="<s:text name="enable"/>" class="btnlist2" id="top_enable_btn"/>
			<input type="button" disabled="disabled" value="<s:text name="disable"/>" class="btnlist2" id="top_disable_btn"/>
		</s:else>
		
		</span>
	</div>
	<div class="listbox" id="listbox">
		<table class="listgrid" id="listbox">
			<tbody>
				<tr>
					<th><input type="checkbox" name="all" id="all_check"/></th>
					<th>编号</th>
					<th width=30%><s:text name="survey.surveyTitle"/></th>
					<th><s:text name="survey.startTime"/></th>
					<th><s:text name="endTime"/></th>
					<th><s:text name="survey.surveyStatus"/></th>
					<th><s:text name="createTime"/></th>
					<th width="260"><s:text name="operate"/></th>
				</tr>
				<s:iterator value="page.result" status="st">
					<tr surveyId="<s:property value="surveyId"/>">
					<td><input type="checkbox" name="key" value="<s:property value="surveyId"/>"/></td>
					<td class="ord"><s:property value="#st.index+1"/></td>
					<td align="left"><s:property value="surveyTitle"/>&nbsp;</td>
					<td><s:property value="startTime"/>&nbsp;</td>
					<td><s:property value="endTime"/>&nbsp;</td>
					<td><s:property value="%{getName(surveyStatus,'SURVEYSTATUS')}"/>&nbsp;</td>
					<td><s:date name="createTime" format="yyyy-MM-dd HH:mm:ss" />&nbsp;</td>
						<td>
						<s:if test="%{authLicence('2_2_4',#siteId)}">
							<a href="#this" onclick="goEdit('survey.surveyId','<s:property value="surveyId"/>')"><s:text name="edit"/></a><tt>|</tt>
						    <a href="#this" onclick="goDelSur('<s:property value="surveyId"/>')"><s:text name="delete"/></a><tt>|</tt>
						   <%--  <a href="#this" onclick="disableOrEnable('<s:property value="surveyId"/>',<s:if test="surveyStatus==1">1</s:if><s:else>2</s:else>);"><s:if test="surveyStatus==1"><s:text name="disable"/></s:if><s:else><s:text name="enable"/></s:else></a><tt>|</tt> --%>
							<a href="#this" onclick="upMove('<s:property value="surveyId"/>', this)" >上移</a><tt>|</tt>
							<a href="#this" onclick="downMove('<s:property value="surveyId"/>', this)" >下移</a>
						</s:if>
						<s:else>
							<s:text name="edit"/><tt>|</tt>
						    <s:text name="delete"/><tt>|</tt>
						    <s:text name="enable"/><tt>|</tt>
						           上移<tt>|</tt>
						   	 下移
						</s:else>
						</td>
					</tr>
				</s:iterator>
			</tbody>
		</table>
	</div>
	<div class="listoperateb ">
		<div class="pager fr"><z:page numberNav="true" selectPageSize="true" input="true" id="ctrl"/></div>
		<span>
		<s:if test="%{authLicence('2_2_4',#siteId)}">
			<input type="button" value="<s:text name="anti-selection"/>" class="btnlist2" id="bottom_anti_btn"/>
			<input type="button" value="<s:text name="delete"/>" class="btnlist2" id="bottom_del_btn"/>
			<input type="button" value="<s:text name="enable"/>" class="btnlist2" id="bottom_enable_btn"/>
			<input type="button" value="<s:text name="disable"/>" class="btnlist2" id="bottom_disable_btn"/>
		</s:if>
		<s:else>
			<input type="button" disabled="disabled" value="<s:text name="anti-selection"/>" class="btnlist2" id="bottom_anti_btn"/>
			<input type="button" disabled="disabled" value="<s:text name="delete"/>" class="btnlist2" id="bottom_del_btn"/>
			<input type="button" disabled="disabled" value="<s:text name="enable"/>" class="btnlist2" id="bottom_enable_btn"/>
			<input type="button" disabled="disabled" value="<s:text name="disable"/>" class="btnlist2" id="bottom_disable_btn"/>
		</s:else>
		</span>
	</div>

</s:form>
</div>
</div>
</body>
</html>
<script type="text/javascript" defer="defer">
	actionName = "survey";	
	confirmStr = "<s:text name="delete.confirm"/>";
	chiocenothing = "<s:text name="chiocenothing"/>";
	$(function(){
 		$("#top_new_btn").click(goNew);
 		$("#top_anti_btn").click(antiSelect);
 		$("#top_del_btn").click(goBatchDel);
 		$("#bottom_del_btn").click(goBatchDel);
 		$("#bottom_anti_btn").click(antiSelect);
		$("#search_btn").click(search);
		$("#all_check").click(selAll);
		$("#extend").click(extend);
		
		$("#top_enable_btn").click(batchEnable);
		$("#top_disable_btn").click(batchDisable);
		$("#bottom_enable_btn").click(batchEnable);
		$("#bottom_disable_btn").click(batchDisable);
	});
	
	
	//禁用/启用
	function disableOrEnable(id,dn){
		var myDate=new Date();
		var sign="";
		if(dn=="1"){
			sign="确实要禁用吗？";
		}else{
			sign="确实要启用吗？";
		}
		if(confirm(sign)){
			$.post("${ctx}/plugins/survey-disableorenable.action?survey.surveyId="+id+"&myTime="+myDate,function(data){
				if(data=="ok"){
					window.location.reload(); 
					alert("成功");
				}else{
					alert("失败");
				}		
			}); 
		}
	}
	
	var g = function(D) {
		if ( D.indexOf(" ") == -1){
			return ( D.substring(0,1) === "#") ? document.getElementById(D.substring(1,D.length)) : document.getElementsByTagName(D);
		}
		else {
			var ary = D.split(" ");
			return g(ary[0]).getElementsByTagName(ary[1]);
		}
	};
	function inputvalue(){
		var d = g("#listbox input"), i = 0, j = d.length, str = "";
	    for ( ; i < j ; i ++ ) {
				str += (d[i].type == "checkbox" && d[i].id != "totalCheck" && d[i].checked == true ) ? d[i].value + "@" : "";
		};	
		return (str.slice(0,-1));
	};
	//批量启用
	function batchEnable(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("请选择要启用的调查主题");
			return; 
		}
		if(!ids){
			alert("您未选择任何一个");
			return;		
		}
		var myDate=new Date();
		if(confirm("确实要启用吗？")){
			$.post("${ctx}/plugins/survey-batchenable.action?ids="+ids+"&myTime="+myDate,function(data){
				if(data=="ok"){
					window.location.reload(); 
					alert("启用成功");
				}else{
					alert("启用失败");
				}		});
		}
		 
	}
	//批量禁用
	function batchDisable(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("请选择要禁用的调查主题");
			return; 
		}
		if(!ids){
			alert("您未选择任何一个");
			return;		
		}
		var myDate=new Date();
		if(confirm("确实要禁用吗？")){
			$.post("${ctx}/plugins/survey-batchdisable.action?ids="+ids+"&myTime="+myDate,function(data){
				if(data=="ok"){
					window.location.reload(); 
					alert("禁用成功");
				}else{
					alert("禁用失败");
				}		
			});
		}
	}
	
	//删除
	function goDelSur(id){
		var myDate=new Date();
		$.post("${ctx}/plugins/surveysubject-allList.action?survey.surveyId="+id+"&myTime="+myDate,function(data){
			if(data=="yes"){
				 if(confirm("该调查主题下包含调查科目,您确定要删除吗？")){
						document.location.href=actionName+"-delete.action?key="+id;
				} 
			}else{
				 if(confirm(confirmStr)){
					document.location.href=actionName+"-delete.action?key="+id;
				} 
			}		
		});
	}
	
	//批量删除
	function goBatchDel(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("请选择要删除的调查主题");
			return; 
		}
		if(!ids){
			return;
		}
		if(confirm("删除就会将主题下的调查栏目以及答案项一同删除,确实要删除吗？")){
			document.location.href="${ctx}/plugins/survey-delete.action?ids="+ids;
		}
	}
	//上移
	function upMove(id, element) {
		var current = $(element).parents("tr");
		var up = current.prev();
		if(up.length != 0 && up.prev().length != 0) {
			var upId = up.attr("surveyId");
			var obj = {"survey.surveyId":id, "upId":upId};
			$.post("${ctx}/plugins/survey-upmove.action", obj, function(data) {
				var ord = current.find(".ord").text();
				current.find(".ord").text(up.find(".ord").text());
				up.find(".ord").text(ord);
				current.insertBefore(up);
			});
		}
	}
	//下移
	function downMove(id, element) {
		var current = $(element).parents("tr");
		var down = current.next();
		if(down.length != 0) {
			var upId = down.attr("surveyId");
			var obj = {"survey.surveyId":id, "upId":upId};
			$.post("${ctx}/plugins/survey-downmove.action", obj, function(data) {
				var ord = current.find(".ord").text();
				current.find(".ord").text(down.find(".ord").text());
				down.find(".ord").text(ord);
				down.insertBefore(current);
			});
		}
	}
	$(function(){
		if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
			$('#main_box').width($('#main_box').width()-25);
		}
	});
	</script>